<!DOCTYPE html> <html lang=zh-CN style><!--
 Page saved with SingleFile 
 url: http://c.biancheng.net/view/9340.html 
 saved date: Mon May 29 2023 20:35:00 GMT+0800 (中国标准时间)
--><meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name=renderer content=webkit>
<meta name=force-rendering content=webkit>
<meta name=applicable-device content=pc,mobile>
<meta name=MobileOptimized content=width>
<meta name=HandheldFriendly content=true>
<meta http-equiv=Cache-Control content=no-transform>
<meta http-equiv=Cache-Control content=no-siteapp>
<meta name=format-detection content="telephone=no">
<style>html{min-height:100%;width:100%}body{margin:0px;padding:0px;min-height:100%;width:100%;font:14px"Helvetica Neue","微软雅黑","Microsoft Yahei",Helvetica,Arial,sans-serif;color:#444;background-color:#fff}h1,h2,h4,p,ol,ul,pre{margin-top:0px;margin-bottom:0px}ul,ol,dd{list-style:none;margin-left:0px;padding-left:0px}a,img{border:none}a{text-decoration:none}a:hover{text-decoration:underline}.hover-none:hover,.hover-none a:hover{text-decoration:none}code{display:inline-block;margin:auto 2px;padding:0px 4px;font-size:100%;color:#333;border:1px solid #ddd;background:#f6f6f6;border-radius:2px;font-family:"Helvetica Neue","微软雅黑","Microsoft Yahei",Helvetica,Arial,sans-serif}.tip-box{margin:10px 0px;padding:10px;border-left:4px solid #ddd;color:#666;background-color:#f9f9f9;border-radius:4px;font-size:14px;word-wrap:break-word}.left{display:block;float:left}.right{display:block;float:right}.clearfix:after{content:"​";display:block;height:0;clear:both}.col-green{color:#008000}.col-link{color:#007dbb}.info-box{padding:10px;margin:6px auto;color:#444;background-color:#f8f8f8;border:1px solid #e1e1e1;border-radius:4px;word-wrap:break-word}@font-face{font-family:"iconfont";src:url(data:font/woff2;base64,d09GMgABAAAAAA4YAAsAAAAAGNAAAA3KAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFQGYACFcgqfaJl/ATYCJANUCywABCAFhGcHgh8b+BQzo3aLtJIn+z8ccH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9K98ojS55qZ3IUBA9LAFZSYl3KIxYlYW/5/3DllRDQRF+28ZdJuk9bUrQz0DBfsbTkozVmT4iRlr5HQtDcUwrNsbyvQAwnrfypRDurmE9LU0t0nQ3Jrov1ZaqfK8+MxmBnDG3azPrxszsnLyCsqUq1CpSrUaterUa9CoSbOiFkjO0FkdL5xPQOv3MIOjQXoTPwEbpKzTA23aCDT1OxbJFpEL2O8ckC2jq4XjLj/N0SQm62LjyW4ufEpwN2vfd68HEqceOOtA/+dpL2VVhzJAb94IneOY8Kwk0m8M1CZaGbb2PpzHkkmTrVI8YCf5OZLmNj0YmTu0ElhJcUSac4GLyK2nbRe5WZcMAQA=)format("woff2")}.iconfont{font-family:"iconfont"!important;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.iconfont-book:before{content:""}.iconfont-vip:before{content:""}.iconfont-home:before{content:""}.iconfont-home2:before{content:""}.iconfont-user:before{content:""}.iconfont-list-vertical:before{content:""}.iconfont-close:before{content:""}.iconfont-c-course:before{content:""}.iconfont-java-course:before{content:""}#topbar{height:36px;line-height:36px;background-color:#335070;border-bottom:1px solid #2f4b69;overflow:visible}#product-type li{float:left}#product-type li.active{height:37px;background-color:#375a7f}#product-type li a{display:inline-block;padding:0px 15px;color:#f9f9f9}#product-type li a .iconfont{padding-right:3px}#ggxc-arctop-pc-1{margin-top:10px}#ggxc-arctop-pc-1 p.small-image{display:flex;flex-wrap:wrap;justify-content:space-between}#ggxc-arctop-pc-1 p.small-image>a{width:49%}#ggxc-arctop-pc-1 p.big-link{padding:8px 10px;margin-top:8px;border:1px #d0d0d0 dashed;background-color:#f9f9f9;line-height:1.6em;border-radius:4px}#ggxc-weixin-arcbottom{margin:20px auto 10px auto;line-height:1.6em}#header{height:42px;width:100%;top:0px;background-color:#375a7f;color:#f3f3f3;z-index:1000;overflow:hidden}#header a{color:#f3f3f3}#logo{height:26px;width:108px;padding:8px 20px}#nav-main li{float:left;line-height:42px}#nav-main li a{display:block;margin-right:10px;padding:0px 6px}.user-info{display:block;float:right;height:42px;margin-right:20px;padding:0px 6px;line-height:42px;font-size:16px}#main{min-width:100%}#sidebar{float:left;padding-bottom:40px;width:20%;border-right:1px solid #ddd}#article-wrap{float:left;padding-bottom:40px;width:79%;margin-left:-1px;border-left:1px solid #ddd}#article{margin-left:20px;width:80%}.arc-info{position:relative;margin-top:18px;padding-bottom:6px;line-height:13px;color:#666;font-size:13px}.arc-info a{color:#666}.arc-info .position{display:block;margin-right:110px}.pre-next-page{padding:8px 0px;line-height:16px;border-bottom:1px solid #ddd;border-top:1px solid #ddd}.pre-next-page a{color:#007dbb}.pre-next-page a .icon{font-size:16px}h1{font-size:26px;line-height:1.6em;font-weight:normal}#arc-body{margin:10px auto;line-height:1.6em}#arc-body h2{margin:15px auto;font-size:24px;line-height:1.6}#arc-body h4{margin:8px auto;font-size:14px;line-height:1.6}#arc-body ul{list-style:disc;padding-left:20px}#arc-body ol{list-style:decimal;padding-left:20px}.box-bottom{border:1px solid #ddd;margin-top:20px}.box-bottom h4{padding-left:12px;background-color:#eee;border-bottom:1px solid #ddd;line-height:2.8em}#nice-arcs ul{padding:7px 0px}#nice-arcs li{width:49%;float:left;height:28px;line-height:28px;overflow:hidden}#nice-arcs li a{display:inline-block;margin:0px 12px}#nice-arcs a{color:#444}#contents dt{height:40px;margin-bottom:6px;padding-left:6px;line-height:40px;font-weight:normal;border-bottom:1px solid #e1e1e1;border-top:1px solid #e1e1e1;background-color:#f8f8f8}#contents dt:first-child{margin-top:0px}#contents dt a{color:#333}#contents dd{margin:auto 12px;line-height:26px}#contents dd a{color:#333}#contents dd.active,#contents dd.active a{color:#D33428}#contents dd span.channel-num{display:block;float:left;margin-top:5px;margin-right:6px;height:16px;width:16px;line-height:16px;text-align:center;font-size:12px;background-color:#777;color:#fff}#footer{padding:20px 90px 20px 30px;border-top:1px solid #e5e5e5;background-color:#f5f5f5}#footer p{font-size:13px;color:#666;line-height:1.6em}#footer p a{color:#3c8cb5}#footer p span{display:inline-block;padding:0px 5px;font-size:12px;color:#777}#logo_bottom{margin-top:8px}#return-top{display:block;position:fixed;right:30px;bottom:30px;height:50px;width:50px;line-height:50px;text-align:center;color:#375a7f;font-size:18px;background-color:#eee;border:1px solid #ddd;border-radius:3px;cursor:pointer;font-family:SimHei}#addweixin-widget{position:fixed;right:10px;top:30%;text-align:center;background-color:#fff}#addweixin-widget p{width:120px;padding:16px 10px 10px 10px;border:1px solid #ccc;border-radius:4px;color:#55ab55}#close-addweixin-widget{display:inline-block;margin-top:4px;font-size:24px;color:#666;cursor:pointer}pre{display:block;padding:0px;margin:0px;font-size:14px;line-height:1.6em;color:#666;white-space:pre-wrap;word-wrap:break-word;background:none;border:none;border-radius:0px}.snippet-wrap{position:relative;margin:5px auto;padding:5px 0px;background-color:#fcfcfc;border:1px solid #ddd;border-radius:3px}.snippet-wrap .snippet-menu{position:absolute;top:0px;right:0px;background-color:#eee;border-left:1px solid #ddd;border-bottom:1px solid #ddd;border-radius:0px 3px 0px 3px;z-index:1}.snippet-wrap .snippet-num{padding:3px 8px 3px 45px!important;background:url()repeat-y}.snippet-wrap .snippet-num li{padding-left:8px;word-wrap:break-word;list-style:decimal-leading-zero outside none}.snippet-wrap .snippet-textonly{padding:3px 10px}.sh_bright .sh_sourceCode .sh_keyword{color:#ff3030;font-weight:bold}.sh_bright .sh_sourceCode .sh_string{color:#1861a7}.sh_bright .sh_sourceCode .sh_specialchar{color:#1861a7}.sh_bright .sh_sourceCode .sh_comment{color:#38ad24}.sh_bright .sh_sourceCode .sh_number{color:#32ba06}.sh_bright .sh_sourceCode .sh_symbol{color:#3030ee}.sh_bright .sh_sourceCode .sh_function{color:#d11ced}.sh_bright .sh_sourceCode .sh_cbracket{color:#3030ee}@media all and (max-width:1250px){#sidebar{width:27%}#article-wrap{width:72%}#article{width:90%}#footer{padding-right:70px}#return-top{right:20px;bottom:20px;height:36px;width:36px;line-height:36px;font-size:16px}#addweixin-widget{display:none}}@media all and (max-width:1200px){#footer{padding:20px}#footer .info{float:none;text-align:center}#footer .info p{margin-top:6px}#logo_bottom{float:none;margin:10px auto 0px auto}}@media all and (max-width:1100px){#sidebar{width:25%}#article-wrap{width:74%}#return-top{right:5px}}@media all and (max-width:769px){body{font-size:16px}#article-wrap{float:none;width:100%;margin-left:0px;border-left:none}#article{margin-left:0px;width:100%}#arc-body{padding:0px 10px;overflow-x:scroll}#sidebar{padding-bottom:8px}#topbar,#ggxc-arctop-pc-1{display:none}#header{height:auto;overflow:visible}#logo{float:none;padding:11px 20px;margin:auto;text-align:center}#nav-main{float:none;padding:4px 0px;border-top:1px solid #2f4b69;background-color:#456c96}#nav-main li{line-height:32px}#nav-main li a{padding:0px 10px;margin-right:0px}.toggle-target{display:none;width:100%!important}.user-info{display:block;position:absolute;top:0px;right:0px;float:none;height:48px;margin-right:0px;padding:0px 15px;line-height:48px;font-size:16px}.arc-info{margin-top:0px;padding:12px 10px;border-bottom:1px solid #ddd;background-color:#f6f6f6}.arc-info .position{white-space:nowrap;overflow:hidden;overflow-x:scroll;-webkit-overflow-scrolling:touch}.pre-next-page{padding:10px 10px;font-size:16px;line-height:18px}.pre-next-page .icon{font-size:18px}h1{padding:0px 10px}#ggxc-weixin-arcbottom{padding:0px 10px;font-size:16px}.box-bottom h4{line-height:2.5em}#nice-arcs li{width:100%;float:none}#sidebar{float:none;background-color:#f6f6f6;border-bottom:1px solid #ddd;border-right:none}pre{overflow:scroll}}</style>
<title>JS数据类型（基本数据类型+引用类型）</title>
<meta name=description content="数据类型指的是可以在程序中存储和操作的值的类型，每种编程语言都有其支持的数据类型，不同的数据类型用来存储不同的数据，例如文本、数值、图像等。 JavaScript 是一种动态类型">
<link rel="shortcut icon" href=""><style>.sf-hidden{display:none!important}</style><link rel=canonical href=http://c.biancheng.net/view/9340.html><meta http-equiv=content-security-policy content="default-src 'none'; font-src 'self' data:; img-src 'self' data:; style-src 'unsafe-inline'; media-src 'self' data:; script-src 'unsafe-inline' data:; object-src 'self' data:; frame-src 'self' data:;"><style>img[src="data:,"],source[src="data:,"]{display:none!important}</style></head>
<body>
<div id=topbar class=clearfix>
<ul id=product-type class=left>
<li>
<a href=http://c.biancheng.net/><span class="iconfont iconfont-home"></span>首页</a>
</li>
<li class=active>
<a href=http://c.biancheng.net/sitemap/ rel=nofollow><span class="iconfont iconfont-book"></span>教程</a>
</li>
<li>
<a href=http://vip.biancheng.net/p/vip/show.php rel=nofollow target=_blank><span class="iconfont iconfont-vip"></span>VIP会员</a>
</li>
<li>
<a href="https://www.54benniao.com/c_course/?from=biancheng" target=_blank><span class="iconfont iconfont-c-course"></span>C语言高级课程</a>
</li>
<li>
<a href="https://www.54benniao.com/java_course/?from=biancheng" target=_blank><span class="iconfont iconfont-java-course"></span>Java高级课程</a>
</li>
</ul>
</div>
<div id=header class=clearfix>
<a id=logo class=left href=http://c.biancheng.net/>
<img height=26 src="" alt=C语言中文网>
</a>
<ul id=nav-main class="hover-none left clearfix">
<li class="wap-yes sf-hidden"></li>
<li><a href=http://c.biancheng.net/c/>C语言教程</a></li>
<li><a href=http://c.biancheng.net/cplus/>C++教程</a></li>
<li><a href=http://c.biancheng.net/python/>Python教程</a></li>
<li><a href=http://c.biancheng.net/java/>Java教程</a></li>
<li><a href=http://c.biancheng.net/linux_tutorial/>Linux入门</a></li>
<li><a href=http://c.biancheng.net/sitemap/ title=网站地图>更多&gt;&gt;</a></li>
</ul>
<span id=sidebar-toggle class="toggle-btn sf-hidden" toggle-target=#sidebar>目录 </span>
<a href="http://vip.biancheng.net/?from=topbar" class="user-info iconfont iconfont-user hover-none" target=_blank rel=nofollow title=用户中心></a>
</div>
<div id=main class=clearfix>
<div id=sidebar class=toggle-target>
<div id=contents>
<dt><span class="iconfont iconfont-list-vertical" aria-hidden=true></span><a href=http://c.biancheng.net/js/>JavaScript</a></dt>
<dd>
<span class=channel-num>1</span>
<a href=http://c.biancheng.net/view/5351.html>JavaScript是什么</a>
</dd>
<dd>
<span class=channel-num>2</span>
<a href=http://c.biancheng.net/view/9338.html>Node.js是什么</a>
</dd>
<dd>
<span class=channel-num>3</span>
<a href=http://c.biancheng.net/view/5355.html>第一个JavaScript程序</a>
</dd>
<dd>
<span class=channel-num>4</span>
<a href=http://c.biancheng.net/view/5359.html>JavaScript中的几个重要概念</a>
</dd>
<dd>
<span class=channel-num>5</span>
<a href=http://c.biancheng.net/view/5370.html>JavaScript注释</a>
</dd>
<dd>
<span class=channel-num>6</span>
<a href=http://c.biancheng.net/view/9339.html>JavaScript变量</a>
</dd>
<dd class=active>
<span class=channel-num>7</span>
<a href=http://c.biancheng.net/view/9340.html>JavaScript数据类型</a>
</dd>
<dd>
<span class=channel-num>8</span>
<a href=http://c.biancheng.net/view/9341.html>JavaScript运算符</a>
</dd>
<dd>
<span class=channel-num>9</span>
<a href=http://c.biancheng.net/view/9342.html>JavaScript输出</a>
</dd>
<dd>
<span class=channel-num>10</span>
<a href=http://c.biancheng.net/view/5505.html>JavaScript if else</a>
</dd>
<dd>
<span class=channel-num>11</span>
<a href=http://c.biancheng.net/view/5526.html>JavaScript switch case</a>
</dd>
<dd>
<span class=channel-num>12</span>
<a href=http://c.biancheng.net/view/9343.html>JavaScript while</a>
</dd>
<dd>
<span class=channel-num>13</span>
<a href=http://c.biancheng.net/view/9344.html>JavaScript do while</a>
</dd>
<dd>
<span class=channel-num>14</span>
<a href=http://c.biancheng.net/view/9345.html>JavaScript for</a>
</dd>
<dd>
<span class=channel-num>15</span>
<a href=http://c.biancheng.net/view/9346.html>JavaScript for in</a>
</dd>
<dd>
<span class=channel-num>16</span>
<a href=http://c.biancheng.net/view/9347.html>JavaScript for of</a>
</dd>
<dd>
<span class=channel-num>17</span>
<a href=http://c.biancheng.net/view/9348.html>JavaScript跳出循环</a>
</dd>
<dd>
<span class=channel-num>18</span>
<a href=http://c.biancheng.net/view/9349.html>JavaScript函数</a>
</dd>
<dd>
<span class=channel-num>19</span>
<a href=http://c.biancheng.net/view/9351.html>JavaScript事件处理</a>
</dd>
<dd>
<span class=channel-num>20</span>
<a href=http://c.biancheng.net/view/9352.html>JavaScript作用域</a>
</dd>
<dd>
<span class=channel-num>21</span>
<a href=http://c.biancheng.net/view/9353.html>JavaScript对象</a>
</dd>
<dd>
<span class=channel-num>22</span>
<a href=http://c.biancheng.net/view/9354.html>JavaScript Number对象</a>
</dd>
<dd>
<span class=channel-num>23</span>
<a href=http://c.biancheng.net/view/9355.html>JavaScript String对象</a>
</dd>
<dd>
<span class=channel-num>24</span>
<a href=http://c.biancheng.net/view/9356.html>JavaScript Array对象</a>
</dd>
<dd>
<span class=channel-num>25</span>
<a href=http://c.biancheng.net/view/9357.html>JavaScript Date对象</a>
</dd>
<dd>
<span class=channel-num>26</span>
<a href=http://c.biancheng.net/view/9358.html>JavaScript Math对象</a>
</dd>
<dd>
<span class=channel-num>27</span>
<a href=http://c.biancheng.net/view/9359.html>JavaScript RegExp对象</a>
</dd>
<dd>
<span class=channel-num>28</span>
<a href=http://c.biancheng.net/view/9360.html>JavaScript DOM</a>
</dd>
<dd>
<span class=channel-num>29</span>
<a href=http://c.biancheng.net/view/9361.html>JavaScript Element对象</a>
</dd>
<dd>
<span class=channel-num>30</span>
<a href=http://c.biancheng.net/view/9362.html>JavaScript attributes对象</a>
</dd>
<dd>
<span class=channel-num>31</span>
<a href=http://c.biancheng.net/view/9363.html>JavaScript BOM</a>
</dd>
<dd>
<span class=channel-num>32</span>
<a href=http://c.biancheng.net/view/9364.html>JavaScript Navigator对象</a>
</dd>
<dd>
<span class=channel-num>33</span>
<a href=http://c.biancheng.net/view/9365.html>JavaScript Screen对象</a>
</dd>
<dd>
<span class=channel-num>34</span>
<a href=http://c.biancheng.net/view/9366.html>JavaScript Location对象</a>
</dd>
<dd>
<span class=channel-num>35</span>
<a href=http://c.biancheng.net/view/9367.html>JavaScript History对象</a>
</dd>
<dd>
<span class=channel-num>36</span>
<a href=http://c.biancheng.net/view/9368.html>JavaScript定时器</a>
</dd>
<dd>
<span class=channel-num>37</span>
<a href=http://c.biancheng.net/view/9369.html>JavaScript异常处理</a>
</dd>
<dd>
<span class=channel-num>38</span>
<a href=http://c.biancheng.net/view/9370.html>JavaScript表单验证</a>
</dd>
<dd>
<span class=channel-num>39</span>
<a href=http://c.biancheng.net/view/9371.html>JavaScript动画</a>
</dd>
<dd>
<span class=channel-num>40</span>
<a href=http://c.biancheng.net/view/9372.html>JavaScript调试</a>
</dd>
<dd>
<span class=channel-num>41</span>
<a href=http://c.biancheng.net/view/9373.html>JavaScript闭包</a>
</dd>
<dd>
<span class=channel-num>42</span>
<a href=http://c.biancheng.net/view/9374.html>JavaScript严格模式</a>
</dd>
<dd>
<span class=channel-num>43</span>
<a href=http://c.biancheng.net/view/9375.html>JavaScript解析JSON</a>
</dd>
<dd>
<span class=channel-num>44</span>
<a href=http://c.biancheng.net/view/9376.html>JavaScript Cookie</a>
</dd>
<dd>
<span class=channel-num>45</span>
<a href=http://c.biancheng.net/view/9377.html>JavaScript Ajax请求</a>
</dd>
<dd>
<span class=channel-num>46</span>
<a href=http://c.biancheng.net/view/9378.html>JavaScript类型转换</a>
</dd>
<dd>
<span class=channel-num>47</span>
<a href=http://c.biancheng.net/view/9379.html>JavaScript事件冒泡与事件捕获</a>
</dd>
<dd>
<span class=channel-num>48</span>
<a href=http://c.biancheng.net/view/9380.html>JavaScript事件委托</a>
</dd>
</div>
</div>
<div id=article-wrap>
<div id=article>
<div class=arc-info>
<span class=position><span class="iconfont iconfont-home2"></span> <a href=http://c.biancheng.net/>首页</a> &gt; <a href=http://c.biancheng.net/js/>JavaScript</a></span>
</div>
<div id=ggxc-position-bottom class="ggxc-box sf-hidden"></div>
<h1>JS数据类型（基本数据类型+引用类型）</h1>
<div class="pre-next-page clearfix"><span class="pre left"><a href=http://c.biancheng.net/view/9339.html><span class=icon>&lt;</span> 上一节</a></span><span class="next right"><a href=http://c.biancheng.net/view/9341.html>下一节 <span class=icon>&gt;</span></a></span></div>
<div id=ggxc-arctop-pc-1 class=ggxc-box><p class=small-image><a href="https://www.54benniao.com/c_course/?from=biancheng" target=_blank><img width=100% src=data:, class=sf-hidden></a><a href="https://www.54benniao.com/java_course/?from=biancheng" target=_blank><img width=100% src=data:, class=sf-hidden></a><p class=big-link><a href="http://c.biancheng.net/view/niz69i.html?from=arctop" target=_blank style=color:#D33428>一套完整的嵌入式开发学习路线（高薪就业版），知识全面，思路清晰，猛击这里免费领取！</a></p></div>
<div id=arc-body>数据类型指的是可以在程序中存储和操作的值的类型，每种编程语言都有其支持的数据类型，不同的数据类型用来存储不同的数据，例如文本、数值、图像等。<br>
<br>
JavaScript 是一种动态类型的语言，在定义变量时不需要提前指定变量的类型，变量的类型是在程序运行过程中由 JavaScript 引擎动态决定的，另外，您可以使用同一个变量来存储不同类型的数据，例如：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> a<span class=sh_symbol>;</span>  <span class=sh_comment>// 此时 a 为 Undefined</span><li>a <span class=sh_symbol>=</span> <span class=sh_string>"http://c.biancheng.net/"</span><span class=sh_symbol>;</span> <span class=sh_comment>// 此时 a 为 String 类型</span><li>a <span class=sh_symbol>=</span> <span class=sh_number>123</span><span class=sh_symbol>;</span>  <span class=sh_comment>// 此时 a 为 Number 类型</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var a;  // 此时 a 为 Undefined
a = "http://c.biancheng.net/"; // 此时 a 为 String 类型
a = 123;  // 此时 a 为 Number 类型</pre></div></div>
JavaScript 中的数据类型可以分为两种类型：<br>
<ul>
<li>
基本数据类型（值类型）：字符串（String）、数字（Number）、布尔（Boolean）、空（Null）、未定义（Undefined）、Symbol；</li>
<li>
引用数据类型：对象（Object）、数组（Array）、函数（Function）。</li>
</ul>
<p class=tip-box>
提示：Symbol 是 ECMAScript6 中引入的一种新的数据类型，表示独一无二的值。</p>
<h4>
typeof 操作符</h4>
在开始介绍各种数据类型之前，先来了解一下 typeof 操作符，使用 typeof 操作符可以返回变量的数据类型。<br>
<br>
typeof 操作符有带括号和不带括号两种用法，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>typeof</span> x<span class=sh_symbol>;</span>       <span class=sh_comment>// 获取变量 x 的数据类型</span><li><span class=sh_keyword>typeof</span><span class=sh_symbol>(</span>x<span class=sh_symbol>);</span>      <span class=sh_comment>// 获取变量 x 的数据类型</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>typeof x;       // 获取变量 x 的数据类型
typeof(x);      // 获取变量 x 的数据类型</pre></div></div>
<h2>
1. JS 基本数据类型</h2>
<h4>
1) String 类型</h4>
字符串（String）类型是一段以单引号<code>''</code>或双引号<code>""</code>包裹起来的文本，例如 '123'、"abc"。需要注意的是，单引号和双引号是定义字符串的不同方式，并不是字符串的一部分。<br>
<br>
定义字符串时，如果字符串中包含引号，可以使用反斜杠<code> \ </code>来转义字符串中的引号，或者选择与字符串中不同的引号来定义字符串，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> str <span class=sh_symbol>=</span> <span class=sh_string>"Let's have a cup of coffee."</span><span class=sh_symbol>;</span>  <span class=sh_comment>// 双引号中包含单引号</span><li><span class=sh_keyword>var</span> str <span class=sh_symbol>=</span> <span class=sh_string>'He said "Hello" and left.'</span><span class=sh_symbol>;</span>    <span class=sh_comment>// 单引号中包含双引号</span><li><span class=sh_keyword>var</span> str <span class=sh_symbol>=</span> <span class=sh_string>'We</span><span class=sh_specialchar>\'</span><span class=sh_string>ll never give up.'</span><span class=sh_symbol>;</span>        <span class=sh_comment>// 使用反斜杠转义字符串中的单引号</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var str = "Let's have a cup of coffee.";  // 双引号中包含单引号
var str = 'He said "Hello" and left.';    // 单引号中包含双引号
var str = 'We\'ll never give up.';        // 使用反斜杠转义字符串中的单引号</pre></div></div>
<h4>
2) Number 类型</h4>
数值（Number）类型用来定义数值，JavaScript 中不区分整数和小数（浮点数），统一使用 Number 类型表示，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> num1 <span class=sh_symbol>=</span> <span class=sh_number>123</span><span class=sh_symbol>;</span>     <span class=sh_comment>// 整数</span><li><span class=sh_keyword>var</span> num2 <span class=sh_symbol>=</span> <span class=sh_number>3.14</span><span class=sh_symbol>;</span>    <span class=sh_comment>// 浮点数</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var num1 = 123;     // 整数
var num2 = 3.14;    // 浮点数</pre></div></div>
<p class=tip-box>
注意：Number 类型所能定义的数值并不是无限的，JavaScript 中的 Number 类型只能表示 -(2<sup>53</sup> - 1) 到 (2<sup>53</sup> -1) 之间的数值。</p>
对于一些极大或者极小的数，也可以通过科学（指数）计数法来表示，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> y<span class=sh_symbol>=</span><span class=sh_number>123e5</span><span class=sh_symbol>;</span>      <span class=sh_comment>// 123 乘以 10 的 5 次方，即 12300000</span><li><span class=sh_keyword>var</span> z<span class=sh_symbol>=</span><span class=sh_number>123e-5</span><span class=sh_symbol>;</span>     <span class=sh_comment>// 123 乘以 10 的 -5 次方，即 0.00123</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var y=123e5;      // 123 乘以 10 的 5 次方，即 12300000
var z=123e-5;     // 123 乘以 10 的 -5 次方，即 0.00123</pre></div></div>
另外，Number 类型中还有一些比较特殊的值，分别为 Infinity、-Infinity 和 NaN，其中<br>
<ul>
<li>
Infinity：用来表示正无穷大的数值，一般指大于 1.7976931348623157e+308 的数；</li>
<li>
-Infinity：用来表示负无穷大的数值，一般指小于 5e-324 的数；</li>
<li>
NaN：即非数值（Not a Number 的缩写），用来表示无效或未定义的数学运算结构，例如 0 除以 0。</li>
</ul>
<p class=tip-box>
提示：如果某次计算的结果超出了 JavaScript 中 Number 类型的取值范围，那么这个数就会自动转化为无穷大，正数为 Infinity，负数为 -Infinity。</p>
<h4>
3) Boolean 类型</h4>
布尔（Boolean）类型只有两个值，true（真）或者 false（假），在做条件判断时使用的比较多，您除了可以直接使用 true 或 false 来定义布尔类型的变量外，还可以通过一些表达式来得到布尔类型的值，例如：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> a <span class=sh_symbol>=</span> <span class=sh_keyword>true</span><span class=sh_symbol>;</span>   <span class=sh_comment>// 定义一个布尔值 true</span><li><span class=sh_keyword>var</span> b <span class=sh_symbol>=</span> <span class=sh_keyword>false</span><span class=sh_symbol>;</span>  <span class=sh_comment>// 定义一个布尔值 false</span><li><span class=sh_keyword>var</span> c <span class=sh_symbol>=</span> <span class=sh_number>2</span> <span class=sh_symbol>&gt;</span> <span class=sh_number>1</span><span class=sh_symbol>;</span>  <span class=sh_comment>// 表达式 2 &gt; 1 成立，其结果为“真（true）”，所以 c 的值为布尔类型的 true</span><li><span class=sh_keyword>var</span> d <span class=sh_symbol>=</span> <span class=sh_number>2</span> <span class=sh_symbol>&lt;</span> <span class=sh_number>1</span><span class=sh_symbol>;</span>  <span class=sh_comment>// 表达式 2 &lt; 1 不成立，其结果为“假（false）”，所以 c 的值为布尔类型的 false</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var a = true;   // 定义一个布尔值 true
var b = false;  // 定义一个布尔值 false
var c = 2 &gt; 1;  // 表达式 2 &gt; 1 成立，其结果为“真（true）”，所以 c 的值为布尔类型的 true
var d = 2 &lt; 1;  // 表达式 2 &lt; 1 不成立，其结果为“假（false）”，所以 c 的值为布尔类型的 false</pre></div></div>
<h4>
4) Null 类型</h4>
Null 是一个只有一个值的特殊数据类型，表示一个“空”值，即不存在任何值，什么都没有，用来定义空对象指针。<br>
<br>
使用 typeof 操作符来查看 Null 的类型，会发现 Null 的类型为 Object，说明 Null 其实使用属于 Object（对象）的一个特殊值。因此通过将变量赋值为 Null 我们可以创建一个空的对象。<br>
<h4>
5) Undefined 类型</h4>
Undefined 也是一个只有一个值的特殊数据类型，表示未定义。当我们声明一个变量但未给变量赋值时，这个变量的默认值就是 Undefined。例如：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> num<span class=sh_symbol>;</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>num<span class=sh_symbol>);</span>  <span class=sh_comment>// 输出 undefined</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var num;
console.log(num);  // 输出 undefined</pre></div></div>
在使用 typeof 操作符查看未赋值的变量类型时，会发现它们的类型也是 undefined。对于未声明的变量，使用 typeof 操作符查看其类型会发现，未声明的变量也是 undefined，示例代码如下：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> message<span class=sh_symbol>;</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span><span class=sh_keyword>typeof</span> message<span class=sh_symbol>);</span>  <span class=sh_comment>// 输出 undefined</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span><span class=sh_keyword>typeof</span> name<span class=sh_symbol>);</span>     <span class=sh_comment>// 输出 undefined</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var message;
console.log(typeof message);  // 输出 undefined
console.log(typeof name);     // 输出 undefined</pre></div></div>
<h4>
6) Symbol 类型</h4>
Symbol 是 ECMAScript6 中引入的一种新的数据类型，表示独一无二的值，Symbol 类型的值需要使用 Symbol() 函数来生成，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> str <span class=sh_symbol>=</span> <span class=sh_string>"123"</span><span class=sh_symbol>;</span><li><span class=sh_keyword>var</span> sym1 <span class=sh_symbol>=</span> <span class=sh_function>Symbol</span><span class=sh_symbol>(</span>str<span class=sh_symbol>);</span><li><span class=sh_keyword>var</span> sym2 <span class=sh_symbol>=</span> <span class=sh_function>Symbol</span><span class=sh_symbol>(</span>str<span class=sh_symbol>);</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>sym1<span class=sh_symbol>);</span>          <span class=sh_comment>// 输出 Symbol(123)</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>sym2<span class=sh_symbol>);</span>          <span class=sh_comment>// 输出 Symbol(123)</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>sym1 <span class=sh_symbol>==</span> sym2<span class=sh_symbol>);</span>  <span class=sh_comment>// 输出 false ：虽然 sym1 与 sym2 看起来是相同的，但实际上它们并不一样，根据 Symbol 类型的特点，sym1 和 sym2 都是独一无二的</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var str = "123";
var sym1 = Symbol(str);
var sym2 = Symbol(str);
console.log(sym1);          // 输出 Symbol(123)
console.log(sym2);          // 输出 Symbol(123)
console.log(sym1 == sym2);  // 输出 false ：虽然 sym1 与 sym2 看起来是相同的，但实际上它们并不一样，根据 Symbol 类型的特点，sym1 和 sym2 都是独一无二的</pre></div></div>
<h2>
2. JS 引用数据类型</h2>
<h4>
1) Object 类型</h4>
JavaScript 中的对象（Object）类型是一组由键、值组成的无序集合，定义对象类型需要使用花括号<code>{ }</code>，语法格式如下：<br>
<p class=info-box>
{name1: value1, name2: value2, name3: value3, ..., nameN: valueN}</p>
其中 name1、name2、name3、...、nameN 为对象中的键，value1、value2、value3、...、valueN 为对应的值。<br>
<br>
在 JavaScript 中，对象类型的键都是字符串类型的，值则可以是任意数据类型。要获取对象中的某个值，可以使用<code> 对象名.键 </code>的形式，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> person <span class=sh_symbol>=</span> <span class=sh_cbracket>{</span><li>    name<span class=sh_symbol>:</span> <span class=sh_string>'Bob'</span><span class=sh_symbol>,</span><li>    age<span class=sh_symbol>:</span> <span class=sh_number>20</span><span class=sh_symbol>,</span><li>    tags<span class=sh_symbol>:</span> <span class=sh_symbol>[</span><span class=sh_string>'js'</span><span class=sh_symbol>,</span> <span class=sh_string>'web'</span><span class=sh_symbol>,</span> <span class=sh_string>'mobile'</span><span class=sh_symbol>],</span><li>    city<span class=sh_symbol>:</span> <span class=sh_string>'Beijing'</span><span class=sh_symbol>,</span><li>    hasCar<span class=sh_symbol>:</span> <span class=sh_keyword>true</span><span class=sh_symbol>,</span><li>    zipcode<span class=sh_symbol>:</span> <span class=sh_keyword>null</span><li><span class=sh_cbracket>}</span><span class=sh_symbol>;</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>person<span class=sh_symbol>.</span>name<span class=sh_symbol>);</span>       <span class=sh_comment>// 输出 Bob</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>person<span class=sh_symbol>.</span>age<span class=sh_symbol>);</span>        <span class=sh_comment>// 输出 20</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var person = {
    name: 'Bob',
    age: 20,
    tags: ['js', 'web', 'mobile'],
    city: 'Beijing',
    hasCar: true,
    zipcode: null
};
console.log(person.name);       // 输出 Bob
console.log(person.age);        // 输出 20</pre></div></div>
<h4>
2) Array 类型</h4>
数组（Array）是一组按顺序排列的数据的集合，数组中的每个值都称为元素，而且数组中可以包含任意类型的数据。在 JavaScript 中定义数组需要使用方括号<code>[ ]</code>，数组中的每个元素使用逗号进行分隔，例如：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_symbol>[</span><span class=sh_number>1</span><span class=sh_symbol>,</span> <span class=sh_number>2</span><span class=sh_symbol>,</span> <span class=sh_number>3</span><span class=sh_symbol>,</span> <span class=sh_string>'hello'</span><span class=sh_symbol>,</span> <span class=sh_keyword>true</span><span class=sh_symbol>,</span> <span class=sh_keyword>null</span><span class=sh_symbol>]</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>[1, 2, 3, 'hello', true, null]</pre></div></div>
另外，也可以使用 Array() 函数来创建数组，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> arr <span class=sh_symbol>=</span> <span class=sh_keyword>new</span> <span class=sh_predef_func>Array</span><span class=sh_symbol>(</span><span class=sh_number>1</span><span class=sh_symbol>,</span> <span class=sh_number>2</span><span class=sh_symbol>,</span> <span class=sh_number>3</span><span class=sh_symbol>,</span> <span class=sh_number>4</span><span class=sh_symbol>);</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>arr<span class=sh_symbol>);</span>       <span class=sh_comment>// 输出 [1, 2, 3, 4]</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var arr = new Array(1, 2, 3, 4);
console.log(arr);       // 输出 [1, 2, 3, 4]</pre></div></div>
数组中的元素可以通过索引来访问。数组中的索引从 0 开始，并依次递增，也就是说数组第一个元素的索引为 0，第二个元素的索引为 1，第三个元素的索引为 2，以此类推。如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> arr <span class=sh_symbol>=</span> <span class=sh_symbol>[</span><span class=sh_number>1</span><span class=sh_symbol>,</span> <span class=sh_number>2</span><span class=sh_symbol>,</span> <span class=sh_number>3.14</span><span class=sh_symbol>,</span> <span class=sh_string>'Hello'</span><span class=sh_symbol>,</span> <span class=sh_keyword>null</span><span class=sh_symbol>,</span> <span class=sh_keyword>true</span><span class=sh_symbol>];</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>arr<span class=sh_symbol>[</span><span class=sh_number>0</span><span class=sh_symbol>]);</span>  <span class=sh_comment>// 输出索引为 0 的元素，即 1</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>arr<span class=sh_symbol>[</span><span class=sh_number>5</span><span class=sh_symbol>]);</span>  <span class=sh_comment>// 输出索引为 5 的元素，即 true</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>arr<span class=sh_symbol>[</span><span class=sh_number>6</span><span class=sh_symbol>]);</span>  <span class=sh_comment>// 索引超出了范围，返回 undefined</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var arr = [1, 2, 3.14, 'Hello', null, true];
console.log(arr[0]);  // 输出索引为 0 的元素，即 1
console.log(arr[5]);  // 输出索引为 5 的元素，即 true
console.log(arr[6]);  // 索引超出了范围，返回 undefined</pre></div></div>
<h4>
3) Function 类型</h4>
函数（Function）是一段具有特定功能的代码块，函数并不会自动运行，需要通过函数名调用才能运行，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>function</span> <span class=sh_function>sayHello</span><span class=sh_symbol>(</span>name<span class=sh_symbol>)</span><span class=sh_cbracket>{</span><li>    <span class=sh_keyword>return</span> <span class=sh_string>"Hello, "</span> <span class=sh_symbol>+</span> name<span class=sh_symbol>;</span><li><span class=sh_cbracket>}</span><li><span class=sh_keyword>var</span> res <span class=sh_symbol>=</span> <span class=sh_function>sayHello</span><span class=sh_symbol>(</span><span class=sh_string>"Peter"</span><span class=sh_symbol>);</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>res<span class=sh_symbol>);</span>  <span class=sh_comment>// 输出 Hello, Peter</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>function sayHello(name){
    return "Hello, " + name;
}
var res = sayHello("Peter");
console.log(res);  // 输出 Hello, Peter</pre></div></div>
此外，函数还可以存储在变量、对象、数组中，而且函数还可以作为参数传递给其它函数，或则从其它函数返回，如下例所示：<br>
<div class=snippet-container style=undefined;><div class="sh_bright snippet-wrap"><div class="snippet-menu sh_sourceCode" style=display:none></div><pre class="javascript sh_javascript snippet-formatted sh_sourceCode"><ol class=snippet-num><li><span class=sh_keyword>var</span> fun <span class=sh_symbol>=</span> <span class=sh_keyword>function</span><span class=sh_symbol>()</span><span class=sh_cbracket>{</span><li>    console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span><span class=sh_string>"http://c.biancheng.net/js/"</span><span class=sh_symbol>);</span><li><span class=sh_cbracket>}</span><li><span style=display:none>&nbsp;</span><li><span class=sh_keyword>function</span> <span class=sh_function>createGreeting</span><span class=sh_symbol>(</span>name<span class=sh_symbol>)</span><span class=sh_cbracket>{</span><li>    <span class=sh_keyword>return</span> <span class=sh_string>"Hello, "</span> <span class=sh_symbol>+</span> name<span class=sh_symbol>;</span><li><span class=sh_cbracket>}</span><li><span class=sh_keyword>function</span> <span class=sh_function>displayGreeting</span><span class=sh_symbol>(</span>greetingFunction<span class=sh_symbol>,</span> userName<span class=sh_symbol>)</span><span class=sh_cbracket>{</span><li>    <span class=sh_keyword>return</span> <span class=sh_function>greetingFunction</span><span class=sh_symbol>(</span>userName<span class=sh_symbol>);</span><li><span class=sh_cbracket>}</span><li><span class=sh_keyword>var</span> result <span class=sh_symbol>=</span> <span class=sh_function>displayGreeting</span><span class=sh_symbol>(</span>createGreeting<span class=sh_symbol>,</span> <span class=sh_string>"Peter"</span><span class=sh_symbol>);</span><li>console<span class=sh_symbol>.</span><span class=sh_function>log</span><span class=sh_symbol>(</span>result<span class=sh_symbol>);</span>  <span class=sh_comment>// 输出 Hello, Peter</span></ol></pre><pre class="snippet-textonly sh_sourceCode" style=display:none>var fun = function(){
    console.log("http://c.biancheng.net/js/");
}

function createGreeting(name){
    return "Hello, " + name;
}
function displayGreeting(greetingFunction, userName){
    return greetingFunction(userName);
}
var result = displayGreeting(createGreeting, "Peter");
console.log(result);  // 输出 Hello, Peter</pre></div></div>
</div>
<div id=ggxc-weixin-arcbottom>
<p>关注公众号「<span class=col-green>站长严长生</span>」，在手机上阅读所有教程，随时随地都能学习。本公众号由<a class=col-link href=http://c.biancheng.net/view/8092.html target=_blank rel=nofollow>C语言中文网站长</a>亲自运营，长期更新，坚持原创。</p>
<p style=margin-top:12px;text-align:center>
<img src="" alt=公众号二维码 width=160><br>
<span class=col-green>微信扫码关注公众号</span>
</p>
</div>
<div class="pre-next-page clearfix"><span class="pre left"><a href=http://c.biancheng.net/view/9339.html><span class=icon>&lt;</span> 上一节</a></span><span class="next right"><a href=http://c.biancheng.net/view/9341.html>下一节 <span class=icon>&gt;</span></a></span></div>
<div id=nice-arcs class=box-bottom>
<h4>推荐阅读</h4>
<ul class=clearfix>
<li><a href=http://c.biancheng.net/view/niz69i.html title=一套完整的嵌入式开发学习路线（高薪就业版） target=_blank>一套完整的嵌入式开发学习路线（高薪就业版）</a></li>
<li><a href=http://c.biancheng.net/view/tnnfqo.html title=一套课程卖1万，TMD太贵了！ target=_blank>一套课程卖1万，TMD太贵了！</a></li>
<li><a href=http://c.biancheng.net/view/unnurw.html title=跑了3000公里，见了一位大佬 target=_blank>跑了3000公里，见了一位大佬</a></li>
<li><a href=http://c.biancheng.net/view/7557.html title=主流嵌入式操作系统有哪些？ target=_blank>主流嵌入式操作系统有哪些？</a></li>
<li><a href=http://c.biancheng.net/view/8776.html title=C语言的主要用途以及未来发展 target=_blank>C语言的主要用途以及未来发展</a></li>
<li><a href=http://c.biancheng.net/view/9480.html title=SaaS模式到底是什么？ target=_blank>SaaS模式到底是什么？</a></li>
<li><a href=http://c.biancheng.net/view/9482.html title=大学是最好的学习时间，错过了悔恨终生 target=_blank>大学是最好的学习时间，错过了悔恨终生</a></li>
<li><a href=http://c.biancheng.net/view/9484.html title=大学生不要为了赚钱而兼职，没有什么卵用！ target=_blank>大学生不要为了赚钱而兼职，没有什么卵用！</a></li>
<li><a href=http://c.biancheng.net/view/9644.html title=为什么中国的996干不过美国的955？ target=_blank>为什么中国的996干不过美国的955？</a></li>
<li><a href=http://c.biancheng.net/view/sqi97i.html title=千万不要这样投资，无数中产瞬间返贫！ target=_blank>千万不要这样投资，无数中产瞬间返贫！</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id=footer class=clearfix>
<div class="info left">
<p>精美而实用的网站，分享优质编程教程，帮助有志青年。千锤百炼，只为大作；精益求精，处处斟酌；这种教程，看一眼就倾心。</p>
<p>
<a href=http://c.biancheng.net/view/8066.html target=_blank rel=nofollow>关于网站</a> <span>|</span>
<a href=http://c.biancheng.net/view/8092.html target=_blank rel=nofollow>关于站长</a> <span>|</span>
<a href=http://c.biancheng.net/view/8097.html target=_blank rel=nofollow>如何完成一部教程</a> <span>|</span>
<a href=http://c.biancheng.net/view/9648.html target=_blank rel=nofollow>公众号</a> <span>|</span>
<a href=http://c.biancheng.net/view/8093.html target=_blank rel=nofollow>联系我们</a> <span>|</span>
<a href=http://c.biancheng.net/sitemap/ target=_blank rel=nofollow>网站地图</a>
</p>
<p>Copyright ©2012-2022 biancheng.net, <a href=https://beian.miit.gov.cn/ target=_blank rel=nofollow style=color:#666>冀ICP备2022013920号</a>, <img height=13 src="" alt=公安备案图标><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=13110202001352" target=_blank rel=nofollow style=color:#666>冀公网安备13110202001352号</a>
</p>
</div>
<img id=logo_bottom class=right src="" alt=底部Logo>
<span id=return-top><b>↑</b></span>
</div>
<div id=addweixin-widget>
<p>
<img src="" alt=微信交流群 width=120><br>
<span>加入微信交流群，一起学习不枯燥。内含一款搜索神器，免费下载全网书籍和视频。</span>
</p>
<span id=close-addweixin-widget class="iconfont iconfont-close"></span>
</div>
<span style=display:none></span>
